#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstdio>
using namespace std;
const int N = 100010;
int e[N], r[N], l[N], idx;
int m;
void ini()
{
    idx = 2;
    r[0] = 1;
    l[1] = 0;
}
void push_front(int x)
{
    e[idx] = x;
    r[idx] = r[0];
    r[0] = idx;
    l[idx] = 0;
    idx++;
}
void push_back(int x)
{
    e[idx] = x;
    l[idx] = l[1];
    r[idx] = 1;
    l[1] = idx;
    idx++;
}
void insertL(int k, int x)
{
    e[idx] = x;
    r[l[k]] = idx;
    l[idx] = l[k];
    r[idx] = k;
    l[k] = idx;
    idx++;
}
void insertR(int k, int x)
{
    e[idx] = x;
    l[r[k]] = idx;
    r[idx] = r[k];
    l[idx] = k;
    r[k] = idx;
    idx++;
}
void pop(int k)
{
    r[l[k]] = r[k];
    l[r[k]] = l[k];
}
int main()
{
    ini();
    scanf("%d", &m);
    while (m--)
    {
        string flag;
        cin >> flag;
        int x, k;
        if (!flag.compare("L"))
        {
            cin >> x;
            push_front(x);
        }
        else if (!flag.compare("R"))
        {
            cin >> x;
            push_back(x);
        }
        else if (!flag.compare("D"))
        {
            cin >> k;
            pop(k);
        }
        else if (!flag.compare("IL"))
        {
            cin >> k >> x;
            insertL(k, x);
        }
        else
        {
            cin >> k >> x;
            insertR(k, x);
        }
    }
    for (int p = r[0]; p != 1; p = r[p])
    {
        printf("%d ", e[p]);
    }
    return 0;
}